package sGUI;

import servidorCorba.ServidorCorba;

public class VentanaServidorCorba extends javax.swing.JFrame
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private javax.swing.JPanel bottomPanel;
	private javax.swing.JPanel centerPanel;
	public static javax.swing.JTextArea console;
	private javax.swing.JScrollPane consoleScroll;
	private javax.swing.JButton stopButton;
	private javax.swing.JLabel tittle;
	private javax.swing.JPanel topPanel;
    
    private String host;
    private String port;
    private String name;
    
    public VentanaServidorCorba(String host, String port, String name)
    {
        
    	initComponents(); 

        this.host = host;
        this.port = port;
        this.name = name;

        try
        {

            showMessage("Servidor Corba funcionando y escuchando en: " + host + ":" + port);            
        }
        
        catch(Exception e)
        {
            showMessage("El servidor no ha podido ser iniciado correctamente.");            
        }
    }    
    
    
    private void initComponents()
    {
        centerPanel = new javax.swing.JPanel();
        consoleScroll = new javax.swing.JScrollPane();
        console = new javax.swing.JTextArea();
        topPanel = new javax.swing.JPanel();
        tittle = new javax.swing.JLabel();
        bottomPanel = new javax.swing.JPanel();
        stopButton = new javax.swing.JButton();

        setTitle("Servidor CORBA de Biblioteca de DEUSTO");
        addWindowListener(new java.awt.event.WindowAdapter() 
        {
            public void windowClosing(java.awt.event.WindowEvent evt) 
            {
                exitForm(evt);
            }
        });

        consoleScroll.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
        consoleScroll.setPreferredSize(new java.awt.Dimension(320, 160));
        console.setBackground(new java.awt.Color(204, 204, 255));
        console.setEditable(false);
        console.setPreferredSize(null);
        consoleScroll.setViewportView(console);

        centerPanel.add(consoleScroll);

        getContentPane().add(centerPanel, java.awt.BorderLayout.CENTER);

        topPanel.setBackground(new java.awt.Color(102, 102, 153));
        topPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(51, 51, 51), 2));
        tittle.setForeground(java.awt.Color.yellow);
        tittle.setText("CONSOLA DEL SERVIDOR DE BIBLIOTECA DE DEUSTO");
        topPanel.add(tittle);

        getContentPane().add(topPanel, java.awt.BorderLayout.NORTH);

        stopButton.setText("Parar");
        stopButton.addActionListener(new java.awt.event.ActionListener() 
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                stopButtonActionPerformed(evt);
            }
        });

        bottomPanel.add(stopButton);

        getContentPane().add(bottomPanel, java.awt.BorderLayout.SOUTH);

        pack();
        this.setEnabled(true);
        this.setVisible(true);
    }

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) 
    {
        ServidorCorba.stopServer();
        System.exit(0);
    }
    
    private void exitForm(java.awt.event.WindowEvent evt) 
    {
        ServidorCorba.stopServer(); 
        System.exit(0);
       
    }
 
    public void showMessage(String message){
        console.append(message + "\n");
    }
    	       
}